package com.zck.thumbup.controller;


import com.zck.thumbup.common.BaseResponse;
import com.zck.thumbup.common.ResultUtils;
import com.zck.thumbup.constant.UserConstant;
import com.zck.thumbup.entity.User;
import com.zck.thumbup.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaochenkang
 * @since 2025-10-16
 */
@RestController
@RequestMapping("/user")

public class UserController {
    @Resource
    private  UserService userService;

    @GetMapping("/login")
    public BaseResponse<User> login(long userId, HttpServletRequest request){
        User user = userService.getById(userId);
        request.getSession().setAttribute(UserConstant.LOGIN_USER_SESSION_KEY, user);
        return ResultUtils.success(user);
    }

    @GetMapping("/get/login")
    public BaseResponse<User> getLoginUser(HttpServletRequest request){
        User loginUser=userService.getLoginUser(request);
        return ResultUtils.success(loginUser);
    }

}
